<?php
	$fName = $_POST['fName'];
	$lName = $_POST['lName'];
	$email = $_POST['email'];
	if(strlen($fName) > 32 || strlen($lName) > 32 || strlen($email) > 16 ||
		strlen($fName) < 1 || strlen($lName) < 1 || strlen($email) < 1)
	{
		$error = "The max length of inputs is 32 characters and the minimum is 1.";
		$error = $error." Emails must be less than 16.";
		$url = "index.php?error=".$error;
		header("Location:".$url);
		die;
	}
	$email = $email."@".$_POST['domain'];
	if (isset($_POST['grad']))
	{
		$grad = "yes";
	} else
	{
		$grad = "no";
	}	
	$gender = $_POST['gender'];

	$insert = "insert into persons(FirstName, LastName, Email, Gender, Graduate) values ";
	$insert = $insert."(?,?,?,?,?)";
	$mysqli = new mysqli('localhost', 'n00659426', 'n00659426', 'n00659426');
	if(!$mysqli)
	{
		echo "Connection failed";
		exit;
	}

	$q=$mysqli->prepare($insert);
	$q->bind_param('sssss', $fName, $lName, $email, $gender, $grad);
	$q->execute();

	$mysqli->close();

	$url = "index.php";
	header("Location: ".$url);
	die;
